/**
  ******************************************************************************
  * @file    disp.c
  * @author  测试1组（houtiezhu）
  * @version v0
  * @date    09-07-2019
  *           
  * @verbatim
  **/
/* Includes ------------------------------------------------------------------*/

#include "define.h"
#include "disp.h"
#include "power.h"
#include "clk.h"
#include "gpio.h"
#include "time.h"
#include "uart.h"
#include "spk.h"
#include "flash.h"
#include "adc.h"
#include "algo.h"
#include "bp.h"
#include "func.h"
#include "op.h"
#include "pwm.h"



uint32 LcdBuf[11];

/*
const uint8  U80EHLCD[] = 
{0xAF,0x06,0x6D,0x4F,0xC6,0xCB,0xEB,0x0E,0xEF,0xCF,0xEE,0x60,0xA9,0x67,0xE9,0xE8,0x00,0xE6,0x02,0xA1,0x63,0x02,0x62,0x40,0xA7,0xE3,0xE1,0xEC,0xAE};
//	 0	 1	  2	  3	   4	  5	  6	   7	  8	   9   A-a  r-b  C-c d-d   E-e	F-f	 -10 H-11 I-12 L-13	o-14 i-15 n-16 --17	U-18  B-19 t-1a	p-1b	N-1c
*/
const uint8 LCDTable[]=
{	
		Char_0,                    // char "0"  0x00
		Char_1,                    // char "1"  0x01
		Char_2,                    // char "2"  0x02
		Char_3,                    // char "3"  0x03
		Char_4,                    // char "4"  0x04
		Char_5,                    // char "5"  0x05
		Char_6,                    // char "6"  0x06
		Char_7,                    // char "7"  0x07
		Char_8,                    // char "8"  0x08
		Char_9,                    // char "9"  0x09
		Char_A,                    // char "A"  0x0a
		Char_R,						//B
       //  Char_B,                    // char "b"  0x0b
		Char_C,                    // char "C"  0x0c
		Char_D,                    // char "d"  0x0d
		Char_E,                    // char "E"  0x0e
		Char_F,                    // char "F"  0x0f
		Char_NULL,				//18
		Char_H,					//10
		Char_I,					//11
		Char_L,					//12
		Char_O,					//13
		Char_i,					//11
		Char_N,					//11
		Char_G,					//11
		Char_U,					//16
		Char_B,                    // char "b"  0x0b
		Char_T,					//16
		Char_P,					//14       
};	


const uint8 LCDTableY[]=
{	
		YChar_0,                    // char "0"  0x00
		YChar_1,                    // char "1"  0x01
		YChar_2,                    // char "2"  0x02
		YChar_3,                    // char "3"  0x03
		YChar_4,                    // char "4"  0x04
		YChar_5,                    // char "5"  0x05
		YChar_6,                    // char "6"  0x06
		YChar_7,                    // char "7"  0x07
		YChar_8,                    // char "8"  0x08
		YChar_9,                    // char "9"  0x09
		YChar_A,                    // char "A"  0x0a
		YChar_R,						//B
       //  Char_B,                    // char "b"  0x0b
		YChar_C,                    // char "C"  0x0c
		YChar_D,                    // char "d"  0x0d
		YChar_E,                    // char "E"  0x0e
		YChar_F,                    // char "F"  0x0f
		YChar_NULL,				//18
		YChar_H,					//10
		YChar_I,					//11
		YChar_L,					//12
		YChar_O,					//13
		YChar_i,					//11
		YChar_N,					//11
		YChar_G,					//11
		YChar_U,					//16
		YChar_B,                    // char "b"  0x0b
		YChar_T,					//16
		YChar_P,					//14       
};	

static void Delayx(uint16 dey)
{
	uint16 k = dey;
	while(k--);
}



void UserLCD_Init(void)
 {
	RCC_APBPeriphClockCmd(RCC_APBPeriph_LCD, ENABLE);   //外设时钟使能
	LCD_DeInit();
	user_lcd_stru_init();
	DarkAllIcon();
	Delayx(1000);
	//ShowAllIcon();
	//LCD_DisALL();
	Delayx(1000);
	/*
	LCD_InitTypeDef LCD_InitStruct; 
	LCD_InitStruct.LCDPin_Mode_COM = 0x000000FF;
	LCD_InitStruct.LCDPin_Mode_SEG1 = 0xFFFFFFF0;
	LCD_InitStruct.LCDPin_Mode_SEG2 = 0x00000FFF;
	LCD_InitStruct.BIAS = ENABLE;
	LCD_InitStruct.LCDBL = ENABLE;
	LCD_InitStruct.LCDDUTY = LCDDUTY_4COM;
	LCD_InitStruct.LCDCLKS_DIV = LCDCLKS_DIV64;
	LCD_InitStruct.LCDCLKS = LCDCLKS_XTOSC1_DIV2;
	
	LCD_Init(&LCD_InitStruct);
	LCD_Cmd(ENABLE);
	
	LCD_VLCDLevelConfig(LCD_VLCDLevel_3V6);
	LCD_CPRCmd(ENABLE);//电荷泵
	*/

 }




void DarkAllIcon(void)
{
	uint8 k;
	for(k=0;k<11;k++)
	{
		LcdBuf[k] = 0;
	}
	LCD->DR0 = 0;
	LCD->DR1 = 0;
	LCD->DR2 = 0;
	LCD->DR3 = 0;
	LCD->DR4 = 0;
	LCD->DR5 = 0;
	LCD->DR6 = 0;
	LCD->DR7 = 0;
	LCD->DR8 = 0;
	LCD->DR9 = 0;
	LCD->DR10 = 0;
	LCD_VLCDLevelConfig(LCD_VLCDLevel_3V6);
}



void ShowAllIcon(void)
{
	uint8 k;
	LCD_VLCDLevelConfig(LCD_VLCDLevel_4V2);
	for(k=0;k<11;k++)
	{
		LcdBuf[k] = 0xFFFFFFFF;
	}
	LCD->DR0 = 0xFFFFFFFF;
	LCD->DR1 = 0xFFFFFFFF;
	LCD->DR2 = 0xFFFFFFFF;
	LCD->DR3 = 0xFFFFFFFF;
	LCD->DR4 = 0xFFFFFFFF;
	LCD->DR5 = 0xFFFFFFFF;
	LCD->DR6 = 0xFFFFFFFF;
	LCD->DR7 = 0xFFFFFFFF;//0x00FFFFFF
	LCD->DR8 = 0xFFFFFFFF;
	LCD->DR9 = 0xFFFFFFFF;
	LCD->DR10 = 0xFFFFFFFF;
	
	if(!UnitSetEnable)
	{
		if(VoiceType!=4)
		{
			kPaIconOff;					//去掉kpa
			if(!UnitIcon) mmHgIconOff;
		}
			kPaPointDIAIconOff;				//去掉点
			kPaPointSYSIconOff;		
	}
	
	if(!PADEnable){PADIconOff;}
	if(!TwoUser){UserAIconOff;UserBIconOff;}
	
	if(!AMPMLCD)
	{
		AMIconOff;
		PMIconOff;
	}
}


void DisplayHalfByte(uint8 LCDData,uint8 position)
{
	if((position < 1)||(position > 22))return;
    if (LCD80Y == 1 && (position == 7 || position == 10))
    {
        if (LCDData > 3 && ( LCDData != 0x10 && LCDData != 0x14))
        {
            return;//特殊处理 sys和dia百位的f点位相连 最大只能显示3 
        }
    }
	if(position == 1)
	{
		LcdBuf[0] = ((LcdBuf[0]&0xFFF1FFFF) |  ((uint32)(LCDTable[LCDData]&0x0F)<<16));//低4位
		LcdBuf[0] = ((LcdBuf[0]&0xF0FFFFFF) |  ((uint32)(LCDTable[LCDData]&0xF0)<<20));
		LCD->DR0 = LcdBuf[0];
	}
	else if(position == 2)
	{
		LcdBuf[1] = ((LcdBuf[1]&0xFFFFFFF1) |    (uint32)(LCDTable[LCDData]&0x0F));//低4位
		LcdBuf[1] = ((LcdBuf[1]&0xFFFFF0FF) |  ((uint32)(LCDTable[LCDData]&0xF0)<<4));//高4位
		LCD->DR1 = LcdBuf[1];
	}
	else if(position == 3)
	{
		LcdBuf[1] = ((LcdBuf[1]&0xFFF1FFFF) |  ((uint32)(LCDTable[LCDData]&0x0F)<<16));//低4位
		LcdBuf[1] = ((LcdBuf[1]&0xF0FFFFFF) |  ((uint32)(LCDTable[LCDData]&0xF0)<<20));
		LCD->DR1 = LcdBuf[1];
	}
	else if(position == 4)
	{
		LcdBuf[2] = ((LcdBuf[2]&0xFFFFF1FF) |    (uint32)(LCDTable[LCDData]&0x0F)<<8);//低4位
		LcdBuf[2] = ((LcdBuf[2]&0xFFF0FFFF) |  ((uint32)(LCDTable[LCDData]&0xF0)<<12));//高4位
		LCD->DR2 = LcdBuf[2];
	}
	else if(position == 5)
	{
		LcdBuf[2] = ((LcdBuf[2]&0xF1FFFFFF) |  ((uint32)(LCDTable[LCDData]&0x0F)<<24));//低4位
		LCD->DR2 = LcdBuf[2];
		LcdBuf[3] = ((LcdBuf[3]&0xFFFFFFF0) |  ((uint32)(LCDTable[LCDData]&0xF0)>>4));
		LCD->DR3 = LcdBuf[3];
	}
	else if(position == 6)
	{
		LcdBuf[3] = ((LcdBuf[3]&0xFFFFF1FF) |    (uint32)(LCDTable[LCDData]&0x0F)<<8);//低4位
		LcdBuf[3] = ((LcdBuf[3]&0xFFF0FFFF) |  ((uint32)(LCDTable[LCDData]&0xF0)<<12));//高4位
		LCD->DR3 = LcdBuf[3];
	}
	else if(position == 7)
	{
		LcdBuf[3] = ((LcdBuf[3]&0xF1FFFFFF) |  ((uint32)(LCDTable[LCDData]&0x0F)<<24));//低4位
		LCD->DR3 = LcdBuf[3];
		LcdBuf[4] = ((LcdBuf[4]&0xFFFFFFF0) |  ((uint32)(LCDTable[LCDData]&0xF0)>>4));
		LCD->DR4 = LcdBuf[4];
        if (LCD80Y == 1)
        {
            LCD->DR3 = LcdBuf[3] &= ~(0x01 << 26);//特殊处理 hour百位的f点位多显示
        }
	}
	else if(position == 8)
	{
		LcdBuf[4] = ((LcdBuf[4]&0xFFFFF1FF) |    (uint32)(LCDTable[LCDData]&0x0F)<<8);//低4位
		LcdBuf[4] = ((LcdBuf[4]&0xFFF0FFFF) |  ((uint32)(LCDTable[LCDData]&0xF0)<<12));//高4位
		LCD->DR4 = LcdBuf[4];
	}
	else if(position == 9)
	{
		LcdBuf[4] = ((LcdBuf[4]&0xF1FFFFFF) |  ((uint32)(LCDTable[LCDData]&0x0F)<<24));//低4位
		LCD->DR4 = LcdBuf[4];
		LcdBuf[5] = ((LcdBuf[5]&0xFFFFFFF0) |  ((uint32)(LCDTable[LCDData]&0xF0)>>4));
		LCD->DR5 = LcdBuf[5];
	}
	else if(position == 10)
	{
		LcdBuf[5] = ((LcdBuf[5]&0xFFFFF1FF) |    (uint32)(LCDTable[LCDData]&0x0F)<<8);//低4位
		LcdBuf[5] = ((LcdBuf[5]&0xFFF0FFFF) |  ((uint32)(LCDTable[LCDData]&0xF0)<<12));//高4位
		LCD->DR5 = LcdBuf[5];
        if (LCD80Y == 1)
        {
            LCD->DR5 = LcdBuf[5] &= ~(0x01 << 10);//特殊处理 sys和dia百位的f点位相连 最大只能显示3
        }
	}
	else if(position == 11)
	{
		LcdBuf[5] = ((LcdBuf[5]&0xF1FFFFFF) |  ((uint32)(LCDTable[LCDData]&0x0F)<<24));//低4位
		LCD->DR5 = LcdBuf[5];
		LcdBuf[6] = ((LcdBuf[6]&0xFFFFFFF0) |  ((uint32)(LCDTable[LCDData]&0xF0)>>4));
		LCD->DR6 = LcdBuf[6];
	}
	//-------------------------- SEG26 Influence    ----------------------------------------//
#ifdef EXCLUDE_SEG2627
	else if(position == 12)
	{
		LcdBuf[6] = ((LcdBuf[6]&0xFFFFF1FF) |    (uint32)(LCDTable[LCDData]&0x0F)<<8);//低4位
		LCD->DR6 = LcdBuf[6];
		LcdBuf[7] = ((LcdBuf[7]&0xFFFFFFF0) |  ((uint32)(LCDTable[LCDData]&0xF0)>>4));//高4位	//S28_C[0][1][2][3]
		LCD->DR7 = LcdBuf[7];
	}
	else if(position == 13)
	{
		LcdBuf[7] = ((LcdBuf[7]&0xFFFFF8FF) |  ((uint32)(LCDTableY[LCDData]&0x0F)<<8));//低4位	//S29_C[0][1][2]
		LcdBuf[7] = ((LcdBuf[7]&0xFFF0FFFF) |  ((uint32)(LCDTableY[LCDData]&0xF0)<<12));		//S30_C[0][1][2][3]
		LCD->DR7 = LcdBuf[7];
	}
	else if(position == 14)
	{
		LcdBuf[7] = ((LcdBuf[7]&0xF8FFFFFF) |    (uint32)(LCDTableY[LCDData]&0x0F)<<24);//低4位	//S31_C[0][1][2]
		LCD->DR7 = LcdBuf[7];
		LcdBuf[8] = ((LcdBuf[8]&0xFFFFFFF0) |  ((uint32)(LCDTableY[LCDData]&0xF0)>>4));//高4位	//S32_C[0][1][2][3]
		LCD->DR8 = LcdBuf[8];
	}
	else if(position == 15)
	{
		LcdBuf[8] = ((LcdBuf[8]&0xFFF8FFFF) |  ((uint32)(LCDTableY[LCDData]&0x0F)<<16));//低4位	//S34_C[0][1][2]
		LcdBuf[8] = ((LcdBuf[8]&0xF0FFFFFF) |  ((uint32)(LCDTableY[LCDData]&0xF0)<<20));		//S35_C[0][1][2][3]
		LCD->DR8 = LcdBuf[8];
	}
	else if(position == 16)
	{
		LcdBuf[9] = ((LcdBuf[9]&0xFFFFFFF8) |    (uint32)((LCDTableY[LCDData]&0x0F)<<0));//低4位	//S36_C[0][1][2]
		LcdBuf[9] = ((LcdBuf[9]&0xFFFFF0FF) |  ((uint32)(LCDTableY[LCDData]&0xF0)<<4));//高4位		//S37_C[0][1][2][3]
		LCD->DR9 = LcdBuf[9];
	}
#else
	else if(position == 12)
	{
		LcdBuf[6] = ((LcdBuf[6]&0xFFFFF1FF) |    (uint32)(LCDTable[LCDData]&0x0F)<<8);//低4位
		LcdBuf[6] = ((LcdBuf[6]&0xFFF0FFFF) |  ((uint32)(LCDTable[LCDData]&0xF0)<<12));//高4位
		LCD->DR6 = LcdBuf[6];
	}
	else if(position == 13)
	{
		LcdBuf[6] = ((LcdBuf[6]&0xF8FFFFFF) |  ((uint32)(LCDTableY[LCDData]&0x0F)<<24));//低4位
		LCD->DR6 = LcdBuf[6];
		LcdBuf[7] = ((LcdBuf[7]&0xFFFFFFF0) |  ((uint32)(LCDTableY[LCDData]&0xF0)>>4));
		LCD->DR7 = LcdBuf[7];
	}
	else if(position == 14)
	{
		LcdBuf[7] = ((LcdBuf[7]&0xFFFFF8FF) |    (uint32)(LCDTableY[LCDData]&0x0F)<<8);//低4位
		LcdBuf[7] = ((LcdBuf[7]&0xFFF0FFFF) |  ((uint32)(LCDTableY[LCDData]&0xF0)<<12));//高4位
		LCD->DR7 = LcdBuf[7];
	}
	else if(position == 15)
	{
		LcdBuf[8] = ((LcdBuf[8]&0xFFFFFFF8) |  ((uint32)(LCDTableY[LCDData]&0x0F)));//低4位
		LcdBuf[8] = ((LcdBuf[8]&0xFFFFF0FF) |  ((uint32)(LCDTableY[LCDData]&0xF0)<<4));
		LCD->DR8 = LcdBuf[8];
	}
	else if(position == 16)
	{
		LcdBuf[8] = ((LcdBuf[8]&0xFFF8FFFF) |    (uint32)((LCDTableY[LCDData]&0x0F)<<16));//低4位
		LcdBuf[8] = ((LcdBuf[8]&0xF0FFFFFF) |  ((uint32)(LCDTableY[LCDData]&0xF0)<<20));//高4位
		LCD->DR8 = LcdBuf[8];
	}
#endif
	
	
	/*
	
	if(position <= 12)//abcdefgX
	{	
		if(position%2 == 1)//奇数对应DR偶数
		{
			//LcdBuf[position ] = ((LcdBuf[position ]&0xFFF1FFFF) |  ((uint32)(LCDTable[LCDData]&0x0F)<<16));//低4位
			//LcdBuf[position ] = ((LcdBuf[position ]&0xF0FFFFFF) |  ((uint32)(LCDTable[LCDData]&0xF0)<<20));
			
			LcdBuf[position ] = ((LcdBuf[position ]&0xFFF1FFFF) |  ((uint32)(0x0F)<<16));//低4位
			LcdBuf[position ] = ((LcdBuf[position ]&0xF0FFFFFF) |  ((uint32)(0xF0)<<20));
			if(position == 1)LCD->DR0 = LcdBuf[position];//DR0-->L
			else if(position == 3)LCD->DR1 = LcdBuf[position ];//DR1-->L
			else if(position == 5)LCD->DR2 = LcdBuf[position ];//DR1-->L
			else if(position == 7)LCD->DR3 = LcdBuf[position - 1];//DR1-->L
			else if(position == 9)LCD->DR4 = LcdBuf[position - 1];//DR1-->L
			else if(position == 11)LCD->DR5 = LcdBuf[position - 1];//DR1-->L
			else if(position == 13)LCD->DR6 = LcdBuf[position - 1];//DR1-->L
			else if(position == 15)LCD->DR7 = LcdBuf[position - 1];//DR1-->L
			else if(position == 17)LCD->DR8 = LcdBuf[position - 1];//DR1-->L
			else if(position == 19)LCD->DR9 = LcdBuf[position - 1];//DR1-->L
			else if(position == 21)LCD->DR10 = LcdBuf[position - 1];//DR1-->L
		}
		else  //if(position%2 == 0)
		{
			//LcdBuf[position ] = ((LcdBuf[position ]&0xFFFFFFF1) |  (uint32)(LCDTable[LCDData]&0x0F));//低4位
			//LcdBuf[position ] = ((LcdBuf[position ]&0xFFFFF0FF) |  ((uint32)(LCDTable[LCDData]&0xF0)<<4));//高4位
			LcdBuf[position ] = ((LcdBuf[position ]&0xFFFFFFF1) |  (uint32)(0x0F));//低4位
			LcdBuf[position ] = ((LcdBuf[position ]&0xFFFFF0FF) |  ((uint32)(0xF0)<<4));//高4位
			if(position == 2)LCD->DR1 = LcdBuf[position];//DR1-->HLCD->DR0 = LcdBuf[position ];//DR0-->H
			else if(position == 4)LCD->DR2 = LcdBuf[position];//DR1-->HLCD->DR1 = LcdBuf[position];//DR1-->H
			else if(position == 6)LCD->DR2 = LcdBuf[position];//DR1-->H
			else if(position == 8)LCD->DR3 = LcdBuf[position - 1];//DR1-->H
			else if(position == 10)LCD->DR4 = LcdBuf[position - 1];//DR1-->H
			else if(position == 12)LCD->DR5 = LcdBuf[position - 1];//DR1-->H
			else if(position == 14)LCD->DR6 = LcdBuf[position - 1];//DR1-->H
			else if(position == 16)LCD->DR7 = LcdBuf[position - 1];//DR1-->H
			else if(position == 18)LCD->DR8 = LcdBuf[position - 1];//DR1-->H
			else if(position == 20)LCD->DR9 = LcdBuf[position - 1];//DR1-->H
			else if(position == 22)LCD->DR10 = LcdBuf[position - 1];//DR1-->H
		}
	}
	else  
	{
		
	}
	*/
	
}



void DisplaySeg(uint8 SegData,uint8 position,uint8 LcdDR)
{
	if(position > 31)return;
	if(LcdDR > 10)return;
	if(SegData)SegData = (SegData&0)| 0x01;
	LcdBuf[LcdDR] = ((LcdBuf[LcdDR]&(~(0x01<<position))) |  (uint32)(SegData<<position));
	if(LcdDR == 0)LCD->DR0 = LcdBuf[LcdDR];
	else if(LcdDR == 1)LCD->DR1 = LcdBuf[LcdDR];
	else if(LcdDR == 2)LCD->DR2 = LcdBuf[LcdDR];
	else if(LcdDR == 3)LCD->DR3 = LcdBuf[LcdDR];
	else if(LcdDR == 4)LCD->DR4 = LcdBuf[LcdDR];
	else if(LcdDR == 5)LCD->DR5 = LcdBuf[LcdDR];
	else if(LcdDR == 6)LCD->DR6 = LcdBuf[LcdDR];
	else if(LcdDR == 7)LCD->DR7 = LcdBuf[LcdDR];
	else if(LcdDR == 8)LCD->DR8 = LcdBuf[LcdDR];
	else if(LcdDR == 9)LCD->DR9 = LcdBuf[LcdDR];
	else if(LcdDR == 10)LCD->DR10 = LcdBuf[LcdDR];
	
}




void LCD5bitDisplay(uint16 TwoByte)
{
	uint8 Temp5;
	uint8 Temp4;
	uint8 Temp3;
	uint8 Temp2;
	uint8 Temp1;
	Temp5=TwoByte/10000;
	Temp4=(TwoByte%10000)/1000;
	Temp3=(TwoByte%1000)/100;
	Temp2=(TwoByte%100)/10;
	Temp1=TwoByte%10;
	DisplayHalfByte(Temp5,7);
	DisplayHalfByte(Temp4,8);
	DisplayHalfByte(Temp3,9);
	DisplayHalfByte(Temp2,11);
	DisplayHalfByte(Temp1,12);
}

void LCD5bitDisplayT(uint16 TwoByte)
{
	uint8 Temp5;
	uint8 Temp4;
	uint8 Temp3;
	uint8 Temp2;
	uint8 Temp1;
	Temp5=TwoByte/10000;
	Temp4=(TwoByte%10000)/1000;
	Temp3=(TwoByte%1000)/100;
	Temp2=(TwoByte%100)/10;
	Temp1=TwoByte%10;
	DisplayHalfByte(Temp5,1);
	DisplayHalfByte(Temp4,2);
	DisplayHalfByte(Temp3,3);
	DisplayHalfByte(Temp2,4);
	DisplayHalfByte(Temp1,5);
}


void LCD8bitDisplay(uint8 DDataH,uint8 DDataM,uint8 DDataL)
{
	uint32	temp9;
	uint8 Temp8;
	uint8 Temp7;
	uint8 Temp6;
	uint8 Temp5;
	uint8 Temp4;
	uint8 Temp3;
	uint8 Temp2;
	uint8 Temp1;
	
	temp9=DDataH*0x10000+DDataM*0x100+DDataL;
	Temp8=temp9/10000000;
	Temp7=(temp9%10000000)/1000000;
	Temp6=(temp9%1000000)/100000;	
	Temp5=(temp9%100000)/10000;
	Temp4=(temp9%10000)/1000;
	Temp3=(temp9%1000)/100;
	Temp2=(temp9%100)/10;
	Temp1=temp9%10;
	
	
	DisplayHalfByte(Temp8,8);
	DisplayHalfByte(Temp7,7);
	DisplayHalfByte(Temp6,5);
	DisplayHalfByte(Temp5,4);
	DisplayHalfByte(Temp4,11);
	DisplayHalfByte(Temp3,10);
	DisplayHalfByte(Temp2,2);
	DisplayHalfByte(Temp1,1);
}


//******************************************************************************
//DisplayToPUL
//******************************************************************************
void DisplayToPUL(unsigned char i)
{	
	unsigned char j;   
	unsigned char ii; 
	ii=i;
			
	DisplayHalfByte(0x10,PulseTen);
	DisplayHalfByte(0x10,PulseSingle);
          
	j=ii%10;
	DisplayHalfByte(j,PulseSingle);
	
	j=(ii/10)%10;
	if((j>0)||(ii>99)||IsCalibrate) 
	{    
		DisplayHalfByte(j,PulseTen);
	}
	j=ii/100;
	if(j==1) {PULBAIIconOn;}
	else{PULBAIIconOff;}		
 	
}
//******************************************************************************
//DisplayToSYSDIA
//******************************************************************************
void DisplayToSYSDIA(unsigned int SYS,unsigned char position)
{
	if(position==1)
		{	
			if(SYS<100) DisplayHalfByte(0x10,SYSHundred);	//显示空
			else 
			{	
				DisplayHalfByte(SYS/100,SYSHundred);
				YIconOff;
				XIconOff;
			}
			
			if(SYS<10&&mmHgkPaFlag){DisplayHalfByte(0x10,SYSTen);}//显示空
			else DisplayHalfByte((SYS/10)%10,SYSTen);
			
			DisplayHalfByte(((SYS%100)%10),SYSSingle);
		}
	if(position==2)
		{	
			if(SYS<100) DisplayHalfByte(0x10,DIAHundred);	//显示空
			else 
			{	
				DisplayHalfByte(SYS/100,DIAHundred);
				YIconOff;
				XIconOff;
			}		
			
			if(SYS<10&&mmHgkPaFlag)	{DisplayHalfByte(0x10,DIATen);}//显示空
			else DisplayHalfByte((SYS/10)%10,DIATen);
			
			DisplayHalfByte(((SYS%100)%10),DIASingle);
		}
}
//******************************************************************************
//DisplayToMemorySet
//******************************************************************************
void DisplayToMemorySet(unsigned int i)
{	
/*	if(LCD80Y)
	{
		if(i<100) DisplayHalfByte(0X10,MemorySetHundred);
		else DisplayHalfByte(i/100,MemorySetHundred);
	}	
*/
//------------------------------------20220705 modify
	if(i<100) {A17_showoff;}
	else if(i/100 == 1) {A17_show1;}
	else if(i/100 == 2) {A17_show2;}	
	else if(i/100 == 3) {A17_show3;}
	else if(i/100 == 4) {A17_show4;}
	else if(i/100 == 5) {A17_show5;}		
	else if(i/100 > 5)  {A17_showoff;}		
//------------------------------------20220705 modify	 
		
	if(i<10) DisplayHalfByte(0x10,MemorySetTen);	//显示空
	else DisplayHalfByte((i%100)/10,MemorySetTen);
	DisplayHalfByte(i%10,MemorySetSingle);
	MemoryIconOn;			//MR icon display
	
}
//******************************************************************************
//DisplayLongSD
//******************************************************************************
void DisplayLongData1(unsigned int i)
{
	DisplayHalfByte(i/10000,MonthSingle);
	DisplayHalfByte((i%10000)/1000,DayTen);
	DisplayHalfByte((i%1000)/100,DaySingle);
	DisplayHalfByte((i%100)/10,HourSingle);
	DisplayHalfByte(i%10,MINTen);	
}
//******************************************************************************
//DisplayLongDT
//******************************************************************************
void DisplayLongData(unsigned int i)
{
	DisplayHalfByte(i/10000,SYSTen);
	DisplayHalfByte((i%10000)/1000,SYSSingle);
	DisplayHalfByte((i%1000)/100,DIAHundred);
	DisplayHalfByte((i%100)/10,DIATen);
	DisplayHalfByte(i%10,DIASingle);	
}
//******************************************************************************
//darkwordtolcdmin
//******************************************************************************
void darkwordtolcdmin(void)
{    
	DisplayHalfByte(0x10,MINSingle);
	DisplayHalfByte(0x10,MINTen);
}
//******************************************************************************
//darkwordtolcdhour
//******************************************************************************
void darkwordtolcdhour(void)
{                 	
	DarkHourTen1;
	DarkHourTen2;
	DisplayHalfByte(0x10,HourSingle);
}
//******************************************************************************
//darkwordtolcdday
//******************************************************************************
void darkwordtolcdday(void)
{                 	
	DisplayHalfByte(0x10,DaySingle);
	DisplayHalfByte(0x10,DayTen);	
}
//******************************************************************************
//darkwordtolcdmonth
//******************************************************************************
void darkwordtolcdmonth(void)
{                 	
	MonthTenIconOff;
	DisplayHalfByte(0x10,MonthSingle);
}
//******************************************************************************
//show minute
//******************************************************************************
void	showminute(void)
{  
        DisplayHalfByte(Minute%10,MINSingle);	
        DisplayHalfByte(Minute/10,MINTen);	
}
//******************************************************************************
//show hour
//******************************************************************************
void	showhour(void)
{      
	unsigned char D;
	D = Hour;
	if(AMPMLCD)
		{
			if(D > 11){D -= 12;}
			if(D == 0) D=12;
		} 
	DarkHourTen1;
	DarkHourTen2;
	DisplayHalfByte(D%10,HourSingle);		
	if(D>19){DisplayHour20;}
	else
        {
			if(D>9){DisplayHourTen1;DisplayHourTen2;}
			else{DarkHourTen1;DarkHourTen2;}
		}      	
//	TimePointIconOn;
	if(AMPMLCD&&(Hour>11)) {PMIconOn;AMIconOff;}	//PM;
	if(AMPMLCD&&(Hour<12)) {AMIconOn;PMIconOff;}	//AM;
}
//******************************************************************************
//show day
//******************************************************************************
void	showday(void)
{
	DisplayHalfByte(Day%10,DaySingle);
  DisplayHalfByte(Day/10,DayTen);
	DayIconOn;
}	
//******************************************************************************
//show month
//******************************************************************************
void	showmonth(void)
{
	DisplayHalfByte(Month%10,MonthSingle);
	if(Month>9) {MonthTenIconOn;}
	else		{MonthTenIconOff;}      
	MonthIconOn;		// display month M
}	
//******************************************************************************
// show time
//******************************************************************************
void	showtime(void) 	
{
	if(!NoTimer)
		{
			showhour();
       		showminute();
		}
}
//******************************************************************************
//show date
//******************************************************************************
void	showdate(void) 
{       
	showday();
	showmonth();      
}
//******************************************************************************
//show year
//******************************************************************************
void	showyear(void)
{ 
	DisplayYear20;						//2
	DisplayHalfByte(0,HourSingle);		//20-Year
	DisplayHalfByte(Year.b%10,MINSingle);	
	DisplayHalfByte(Year.b/10,MINTen);	
}

//******************************************************************************
//flash minute
//******************************************************************************
void	flashminute(void)
{       
	if (T250ms == 0)
	{
		if (OneShot == 1)
		{
			showminute();			// if 1/4 second to show minute process 
			OneShot=0;
		}
	}
	else
	{
	   	if (OneShot == 0)			// if one shot flag = 0 then 
	     	{
	      		OneShot = 1;		// set on shot flag = 1 
	      		darkwordtolcdmin();	// dark minute digit on LCD 
	     	}
	}

}

//******************************************************************************
//flash minute
//******************************************************************************
void	flashtimepoint(void)
{       
			if(fRTC_500ms==1) TimePointIconOn;
			else TimePointIconOff;	
}
//******************************************************************************
// flash hour
//******************************************************************************
void	flashuser(void)
{   
    
	if (T250ms == 0)
	{
		if (OneShot == 1)				// if one shot flag = 0 then 
	     	{
				UserABDisplay();
				OneShot=0;
	     	}
	}
	else
	{
	   	if (OneShot == 0)				// if one shot flag = 0 then 
	     	{
	      		OneShot = 1;			// set on shot flag = 1 
						UserAIconOff;
						UserBIconOff;
	     	}
	}

}

void	flashmemoryset(unsigned char i)
{       
	if (T250ms == 0)
	{
		if (OneShot == 1)				// if one shot flag = 0 then 
	     	{
					DisplayToMemorySet(i);
					DisplayHalfByte(0xC,DIAHundred);
					DisplayHalfByte(0x13,DIATen);
					DisplayHalfByte(0xb,DIASingle);
					OneShot=0;
	     	}
	}
	else
	{
	   	if (OneShot == 0)				// if one shot flag = 0 then 
	     	{
	      		OneShot = 1;			// set on shot flag = 1 
						MemoryIconOff;
						DisplayHalfByte(0x10,MemorySetTen);
						DisplayHalfByte(0x10,MemorySetSingle);
						if(KeyNumber==12)
						{
							DisplayHalfByte(0x10,DIAHundred);
							DisplayHalfByte(0x10,DIATen);
							DisplayHalfByte(0x10,DIASingle);
						}
	     	}
	}
}
void	flashhour(void)
{       
	if (T250ms == 0)
	{
		if (OneShot == 1)				// if one shot flag = 0 then 
		{
		 	showhour();					// if 1/4 second to show hour process 
		 	OneShot=0;
		}
	}
	else
	{
	   	if (OneShot == 0)				// if one shot flag = 0 then 
	     	{
	      		OneShot = 1;			// set on shot flag = 1 
	      		darkwordtolcdhour();	// dark hour digit on LCD 
				if(KeyNumber==11||KeyNumber==12) {AMIconOff;PMIconOff;}
	     	}
	}
	TimePointIconOn;
	if(KeyNumber!=11&&KeyNumber!=12)
	{
		if(AMPMLCD&&(Hour>11)) {PMIconOn;AMIconOff;}	//PM;
		if(AMPMLCD&&(Hour<12)) {AMIconOn;PMIconOff;}	//AM;
	}
}

//******************************************************************************
//flash day
//******************************************************************************
void	flashday(void)
{       
	if (T250ms == 0)
	{
	  	if (OneShot == 1)
	  	{
	  		OneShot=0; 
	  		showday();		
	  	}
	}
	else
	{
	   	if (OneShot == 0)		
		{
	      		OneShot = 1;		
	      		darkwordtolcdday();	
		}
	}
	DayIconOn; 
}

//******************************************************************************
//flash month
//******************************************************************************
void	flashmonth(void)
{
	
	if (T250ms == 0)
	{
		if (OneShot == 1)		// if one shot flag = 0 then 
		{
		 	showmonth();	// if 1/4 second to show month process 
		 	OneShot = 0;
		}
	}
	else
	{
	  	if (OneShot == 0)		// if one shot flag = 0 then 
		{
	     	OneShot = 1;		// set on shot flag = 1 
	     	darkwordtolcdmonth();	// dark hour digit on LCD 
		}
	}
	MonthIconOn;
	DayIconOn;
}
//******************************************************************************
//flash year
//******************************************************************************
void	flashyear(void)
{	
	if (T250ms == 0)
	{
		if (OneShot == 1)			
	     	{
				OneShot = 0;
				showyear();					 
	     	}
	}
	else
	{
	   	if (OneShot == 0)				 
	     	{	      	
	      		OneShot = 1;
				//DarkAllIcon();
	      		darkwordtolcdhour();	
	      		darkwordtolcdmin();		 
	     	}
	}                
}

//************************************************/
void	flashParameter(void)
{       
	if (T250ms == 0)
		{
			if (OneShot == 1)					
	     	{
					DisplayToSYSDIA(BB,2);				 
					OneShot=0;
	     	}
		}
	else
		{
	   	if (OneShot == 0)				
	     	{
	      		OneShot = 1;			
	      		DisplayHalfByte(0x10,DIASingle);
				DisplayHalfByte(0x10,DIATen);
				DisplayHalfByte(0x10,DIAHundred);
	     	}
	}
}

void UserABDisplay(void)
{	
	if(TwoUser==1)
		{
			if(UserA==1){UserAIconOn;UserBIconOff;}
			else{UserBIconOn;UserAIconOff;}
		}
	else{UserAIconOff;UserBIconOff;}
}

void ShowVoice(void)
{
	if(KeyNumber==7&&VoiceSetEnable)
	{
		if(VoiceEnable) VoiceOffIconOff;
		else VoiceOffIconOn;
	}
}



void showpressure(void)
{
	if (T125ms == 0) OneShotDC = 0;
	else
	{
		if (OneShotDC == 0)
	     	{
	      		OneShotDC = 1;
	      		showpres();
	      		CheckBatteryCOM();
	     	}
	}	
}


void mmHgKpaDisplay(unsigned char SysDisplay,unsigned char DiaDisplay)
{
	unsigned int 	TempSYS;
	unsigned int	TempDIA;
	if(KeyNumber!=7&&!LCDType2&&!BTIconEnable) ResultIcon3On;
	if(mmHgkPaFlag==1)
		{
			DisplayToSYSDIA(SysDisplay,1);		//mmHg
			DisplayToSYSDIA(DiaDisplay,2);
				if(UnitSetEnable||UnitIcon) mmHgIconOn;					//mmHg
				kPaIconOff;					//去掉kpa
				kPaPointDIAIconOff;				//去掉点
				kPaPointSYSIconOff;				//去掉点
		}
	else
		{
			TempSYS=SysDisplay;
			TempDIA=DiaDisplay;
			TempSYS*=4;
			TempSYS/=3;
			TempDIA*=4;
			TempDIA/=3;
											
			DisplayToSYSDIA(TempSYS,1);		//20101211新增Kpa显示
			DisplayToSYSDIA(TempDIA,2);	
			mmHgIconOff;	//去掉mmHg
			kPaIconOn;		//kpa
			kPaPointSYSIconOn;	//点
			kPaPointDIAIconOn;
		}
}


void	showpres(void) 
{  
	unsigned int TempPressure;
	TempPressure= PressuremmHgw;
	if(BPTestFlag)
	{
		if(TempPressure>=300) TempPressure=299;
	}
	if(mmHgkPaFlag==1)
		{
		  DisplayToSYSDIA(TempPressure,2);	
			if(UnitSetEnable||UnitIcon) {if(!LCD80Y) mmHgIconOn;}			
		}
	else
		{		
			TempPressure*=4;
			TempPressure/=3;
			DisplayToSYSDIA(TempPressure,2);
			if(!LCD80Y) kPaIconOn;							//kpa
			kPaPointDIAIconOn;
		}
	UserABDisplay();
	ShowVoice();
	if(KeyNumber==7) ShowPumpWHO();
}


void ShowPumpWHO(void)
{
	if(PressuremmHgw>=165) BAR1IconOn;
	else BAR1IconOff;
	if(PressuremmHgw>=150) BAR2IconOn;
	else BAR2IconOff;
	if(PressuremmHgw>=135) BAR3IconOn;
	else BAR3IconOff;
	if(PressuremmHgw>=115) BAR4IconOn;
	else BAR4IconOff;
	if(PressuremmHgw>=100) BAR5IconOn;
	else BAR5IconOff;
	if(PressuremmHgw>=85) BAR6IconOn;
	else BAR6IconOff;
	if(PressuremmHgw>=70) BAR7IconOn;
	else BAR7IconOff;
	BAR8IconOn;
}	


void	Calshowpres(void) 
{   
	unsigned char temp;
	temp=PressuremmHgw%10;
	DisplayToSYSDIA(PressuremmHgw/10,2);
	DisplayHalfByte(temp,PulseSingle);     	
}


void ShowBTBar(void)
{
	switch(ShowBTLevel)
	{
		case 1:
			WHOLevelIconOff;
			WHOLevel1Icon;
			return;
		case 2:
			WHOLevelIconOff;
			WHOLevel2Icon;
			return;
		case 3:
			WHOLevelIconOff;
			WHOLevel3Icon;
			return;
		case 4:
			WHOLevelIconOff;
			WHOLevel4Icon;
			return;
		case 5:
			WHOLevelIconOff;
			WHOLevel4Icon;
			WHOLevel5Icon;
			return;
		case 6:
			WHOLevelIconOff;
			WHOLevel4Icon;
			WHOLevel6Icon;
			return;
	}
}



void heartsignon(void)
{
	HeartIconOn;
}

void heartsignoff(void)
{     
	HeartIconOff;
}



void mmHgKpaSetDisplay(void)
{
		if(mmHgkPaFlag==1)
		{
			DisplayHalfByte(0,SYSSingle);
			DisplayHalfByte(0,DIASingle);
			DisplayHalfByte(0x10,SYSTen);
			DisplayHalfByte(0x10,DIATen);
			if(UnitSetEnable||UnitIcon) mmHgIconOn;					//mmHg
			kPaIconOff;					//去掉kpa
			kPaPointDIAIconOff;			//去掉点
			kPaPointSYSIconOff;			//去掉点		
		}
		else
		{
			DisplayHalfByte(0,SYSTen);
			DisplayHalfByte(0,DIATen);
			DisplayHalfByte(0,SYSSingle);
			DisplayHalfByte(0,DIASingle);
			mmHgIconOff;				//kpa
			kPaIconOn;					//去掉mmHg
			kPaPointSYSIconOn;				//点
			kPaPointDIAIconOn;
		}
}

void	showerror(void)
{
	unsigned char i;	
	BPTestFlag=0;
	AutoOffTimew=0x0000;
	AutoTestFlag=0;
	DarkAllIcon();
	
	OutRedOn;//OutRed=1;
	OutGreenOff;//OutGreen=0;
	if(BPLevelType==5) LedOff;
	//if(ConnectFlag&&BTIconEnable) BTIconOn;	
	BB= VALVEOFF | PUMPOFF;          
	iocontroloff();   	
//	DisplayHalfByte(0xe,DIAHundred);			/* 'E' */
//	DisplayHalfByte(0x17,DIATen);			/* '-' */
//	DisplayHalfByte(ResultCode,DIASingle);	//错误代码	
	
	DisplayHalfByte(0xe,SYSTen);			/* 'E' */ //20220704 ModifyFlag
	DisplayHalfByte(0x17,SYSSingle);			/* '-' */
	DisplayHalfByte(ResultCode,DIASingle);	//错误代码	
	
	for(i=0;i<5;i++)
	{			                        /* show Err to left digit on LCD */	
		BUZZER_EN; 		/* buzzer 3/4 second beep then delay 3/8 second */
		delay(8);
		BUZZER_DIS;
		delay(8);
	}
	SendMemoryFlag=0;
	BTFlag=0;
	if(UartType==1||UartType==4||UartType==5||UartType==6) 
	{
		Send_ErrorCode();
		RXIEnable;
		BTFlag=0;
	}
	
	if((VoiceEnable==1)&&((ResultCode==1)||(ResultCode==2)||(ResultCode==3)||(ResultCode==5)))
		{
			if(VoiceType==1||VoiceType==12||VoiceType==14) 
			{	
				if((VoiceType==1) && (VoiceType2==2)) 		//20230508	CN+MD
				{	
					SoundCommand(0xCE);							
				}
                else if(VoiceType==1&&VoiceType2==3) 
                {
                    volume_adjus_china_eng_malay(VoiceLevel);//中语英语马来西亚语音量调节
                    SoundCommand(0xD8);
                }//D8H测量时侦测到错误, 请休息兩分钟后, 再重新量测
				else
				{
					SoundCommand(0xE6);				
				}				
			}
			else if(VoiceType>=2&&VoiceType<=4) SoundCommand(0x8E);
			else if(VoiceType==5) SoundAllCommand(0x22,0,0,0);
			else if(VoiceType==7) SoundCommand(0xBE);
			else if(VoiceType==6) SoundCommand2(0xE6);
			else if(VoiceType==8&&VoiceFlag<5) {SoundFive();SoundCommand2(0xCE);}
			else if(VoiceType==9) SoundCommand(0xCF);
			else if(VoiceType==10) SoundCommand(0x8E);	//Error,(Mistake ),Please measure again
			else if(VoiceType==11) SoundCommand2(0xCF);
			else if(VoiceType==13&&VoiceLevel>0) {SoundThree();SoundCommand2(0xE3);}
			
		}//测量时侦测到错误,请休息兩分钟后,再重新量测
		
	AutoOffTimew = 0x0000;

	N=0;
	KeyIn=1;
	KeyModeFlag.b=0;
	do{
			delay(1);
			if(UartType==5&&WorkMode==1) break;
			if(AutoOffTimew>AUTOOFFTIME&&!AllTimeFlag) break;
		
			if(KeyNumber==11)
			{
				if(!KEY_MEMORYUP||!KEY_MEMORYDOWN) {MemoryKeyFlag=1;break;}
				if(LongSetFlag) {SetKeyFlag=1;break;}
			}
			if(KeyNumber==12)
			{
				if(!KEY_TIME) {MemoryKeyFlag=1;break;}
			}
		
	}while(IsPowerOn&&KEY_POWER&&!BTFlag&&!SendMemoryFlag);
		  
	IsShowPressure = 0; 	/* set show pressure flag = 0 */
	IsAlgorithm = 0;		/* set algorithm flag = 0 */
	IsAlgoEnd = 0;		/* set algorithm enf flag = 0 */

	DarkAllIcon();		/* dark all pattern on LCD */ 
//	showtime();       

	IsPowerOn=0;
	//showtime();		
       	//ShowAVG = 1;
}

void   ShowWHO(unsigned char WHOSYS,unsigned char WHODIA)
{
	FreWho130Flag = 0;
	if(LCD80Y){ ResultIcon2On;}
	#if 0
		if(VoiceType==10)
		{
			SLevel=0;
			if(WHOSYS<90&&WHODIA<50)
			{
				SLevel=1;
			}
			if(WHOSYS>=90&&WHOSYS<140&&WHODIA<50)
			{
				SLevel=2;
			}
			if(WHOSYS>=140&&WHODIA<50)
			{
				SLevel=3;
			}
			if(WHOSYS<90&&WHODIA>=50&&WHODIA<90)
			{
				SLevel=4;
			}
		}	
	#endif
		if(KeyNumber==7)
		{
			if(WHOSYS>165){BAR8IconOn;BAR7IconOn;BAR6IconOn;BAR5IconOn;BAR4IconOn;BAR3IconOn;BAR2IconOn;BAR1IconOn;}
			else if(WHOSYS>150){BAR8IconOn;BAR7IconOn;BAR6IconOn;BAR5IconOn;BAR4IconOn;BAR3IconOn;BAR2IconOn;BAR1IconOff;}
			else if(WHOSYS>135){BAR8IconOn;BAR7IconOn;BAR6IconOn;BAR5IconOn;BAR4IconOn;BAR3IconOn;BAR2IconOff;BAR1IconOff;}
			else if(WHOSYS>115){BAR8IconOn;BAR7IconOn;BAR6IconOn;BAR5IconOn;BAR4IconOn;BAR3IconOff;BAR2IconOff;BAR1IconOff;}
			else if(WHOSYS>100){BAR8IconOn;BAR7IconOn;BAR6IconOn;BAR5IconOn;BAR4IconOff;BAR3IconOff;BAR2IconOff;BAR1IconOff;}
			else if(WHOSYS>85){BAR8IconOn;BAR7IconOn;BAR6IconOn;BAR5IconOff;BAR4IconOff;BAR3IconOff;BAR2IconOff;BAR1IconOff;}
			else if(WHOSYS>70){BAR8IconOn;BAR7IconOn;BAR6IconOff;BAR5IconOff;BAR4IconOff;BAR3IconOff;BAR2IconOff;BAR1IconOff;}
			else{BAR8IconOn;BAR7IconOff;BAR6IconOff;BAR5IconOff;BAR4IconOff;BAR3IconOff;BAR2IconOff;BAR1IconOff;}

			if(WHODIA>165){BAR2IconOff;BAR3IconOff;BAR4IconOff;BAR5IconOff;BAR6IconOff;BAR7IconOff;BAR8IconOff;}		
			else if(WHODIA>150){BAR3IconOff;BAR4IconOff;BAR5IconOff;BAR6IconOff;BAR7IconOff;BAR8IconOff;}
			else if(WHODIA>135){BAR4IconOff;BAR5IconOff;BAR6IconOff;BAR7IconOff;BAR8IconOff;}
			else if(WHODIA>115){BAR5IconOff;BAR6IconOff;BAR7IconOff;BAR8IconOff;}
			else if(WHODIA>100){BAR6IconOff;BAR7IconOff;BAR8IconOff;}
			else if(WHODIA>85){BAR7IconOff;BAR8IconOff;}
			else if(WHODIA>70){BAR8IconOff;}
		}
		if(BPLevelType==0) return;											//无显示WHO符号
		if(BPLevelType==2) goto BPLevelTypeis5;					//2表示5格； 否则6格
		if(BPLevelType==4)
		{
			goto Type4;
		}
		//*************************************************6 格	
		if((WHOSYS>=WHOSYS5)||(WHODIA>=WHODIA5))
			{
				if(KeyNumber!=7) 
					{
						WHOLevel6Icon;
						WHOLevel5Icon;
					}
				if(KeyNumber!=7) 
					{
						WHOLevel4Icon;
						WHOLevel3Icon;
						WHOLevel2Icon;
						WHOLevel1Icon;
					}
				if(VoiceType==1||VoiceType==6||VoiceType==7||VoiceType==6||VoiceType==14)
				{	
					if((VoiceType==1) && (VoiceType2==2))		//20230510
					{	
						WHOLevel=6;					
					}
					else
					{	
						WHOLevel=5;					
					}											
				}					
				else if((VoiceType>=2&&VoiceType<=5)||VoiceType==8||VoiceType==11) WHOLevel=6;
				else if(VoiceType==9) WHOLevel=3;
				else if(VoiceType==13&&VoiceFlag>0) WHOLevel=3;
				else WHOLevel=5;
				
				if(BPLevelType==5)
				{
					LedOff;
					OutGreenOff;//OutGreen=0;
					OutRedOn;//OutRed=1;
				}
				else
				{
					if(BLFlag||KeyNumber==7)
					{
						OutGreenOff;//OutGreen=0;
						OutRedOn;//OutRed=1;
					}
				}
				return;
			}	
		if((WHOSYS>=WHOSYS4)||(WHODIA>=WHODIA4))
			{
				if(KeyNumber!=7) WHOLevel5Icon;
				if(KeyNumber!=7) 
					{
						WHOLevel4Icon;
						WHOLevel3Icon;
						WHOLevel2Icon;
						WHOLevel1Icon;
					}
				if(VoiceType==1||VoiceType==6||VoiceType==7||VoiceType==14)
				{
					if((VoiceType==1) && (VoiceType2==2))		//20230510
					{	
						WHOLevel=5;					
					}
					else
					{	
						WHOLevel=4;					
					}					
				}					
				else if((VoiceType>=2&&VoiceType<=5)||VoiceType==8||VoiceType==11) WHOLevel=5;
				else if(VoiceType==9) WHOLevel=4;
				else WHOLevel=4;
				
				if(BPLevelType==5)
				{
					LedOff;
					OutGreenOff;//OutGreen=0;
					OutRedOn;//OutRed=1;
				}
				else
				{
					if(BLFlag||KeyNumber==7)
					{
						OutGreenOff;//OutGreen=0;
						OutRedOn;//OutRed=1;
					}
				}
				return;
			}		
		if((WHOSYS>=WHOSYS3)||(WHODIA>=WHODIA3))
			{
				if(KeyNumber!=7) 
					{
						WHOLevel4Icon;
						WHOLevel3Icon;
						WHOLevel2Icon;
						WHOLevel1Icon;
					}
				if(VoiceType==1||VoiceType==6||VoiceType==7||VoiceType==14) 
				{
					if((VoiceType==1) && (VoiceType2==2))		//20230510
					{	
						WHOLevel=4;					
					}
					else
					{	
						WHOLevel=3;					
					}					
				}
				else if((VoiceType>=2&&VoiceType<=5)||VoiceType==8||VoiceType==11) WHOLevel=4;
				else if(VoiceType==9) WHOLevel=4;
				else if(VoiceType==13&&VoiceFlag>0) WHOLevel=2;
				else WHOLevel=3;
				
				if(BPLevelType==5)
				{
					LedOff;
					OutGreenOff;//OutGreen=0;
					OutRedOn;//OutRed=1;
				}
				else
				{
					if(BLFlag||KeyNumber==7)
					{
						OutGreenOff;//OutGreen=0;
						OutRedOn;//OutRed=1;
					}
				}
				return;
			}			
		if((WHOSYS>=WHOSYS2)||(WHODIA>=WHODIA2))
			{
				if(KeyNumber!=7) 
					{
						WHOLevel3Icon;
						WHOLevel2Icon;
						WHOLevel1Icon;
					}
				if(VoiceType==1||VoiceType==6||VoiceType==7||VoiceType==14) 
				{
					if((VoiceType==1) && (VoiceType2==2))		//20230510
					{	
						WHOLevel=3;					
					}
					else
					{	
						WHOLevel=2;					
					}					
				}
				else if((VoiceType>=2&&VoiceType<=5)||VoiceType==8||VoiceType==11) WHOLevel=3;
				else if(VoiceType==9) WHOLevel=2;
				else WHOLevel=2;
				
				FreWho130Flag = 1;
				
				if(BPLevelType==5)
				{
					LedOff;
					OutGreenOn;//OutGreen=1;
					OutRedOff;//OutRed=0;
				}
				else
				{
					if(BLFlag||KeyNumber==7)
					{
						OutGreenOn;//OutGreen=1;
						OutRedOn;//OutRed=1;
					}
				}
				return;
			}				
		if((WHOSYS>=WHOSYS1)||(WHODIA>=WHODIA1))
			{
				if(KeyNumber!=7) 
					{
						WHOLevel2Icon;
						WHOLevel1Icon;
					}
				if(VoiceType==1||VoiceType==6||VoiceType==7||VoiceType==14) WHOLevel=1;
				else if((VoiceType>=2&&VoiceType<=5)||VoiceType==8||VoiceType==11) WHOLevel=2;
				else if(VoiceType==9) WHOLevel=1;
				else WHOLevel=1;
				if(BPLevelType==5)
				{
					LedOn;
					OutGreenOff;//OutGreen=0;
					OutRedOff;//OutRed=0;
				}
				else
				{
					if(BLFlag||KeyNumber==7)
					{
						OutGreenOn;//OutGreen=1;
						OutRedOff;//OutRed=0;
					}
				}
				return;
			}			
		if((WHOSYS<WHOSYS1)&&(WHODIA<WHODIA1))
			{
				if(KeyNumber!=7) WHOLevel1Icon;
				WHOLevel=1;
				if(BPLevelType==5)
				{
					LedOn;
					OutGreenOff;//OutGreen=0;
					OutRedOff;//OutRed=0;
				}
				else
				{
					if(BLFlag||KeyNumber==7)
					{
						OutGreenOn;//OutGreen=1;
						OutRedOff;//OutRed=0;
					}
				}
				if(WHOSYS<80&&WHODIA<50)
				{
					if(VoiceType==13&&VoiceFlag>0) WHOLevel=5;
				}
				return;
			}
BPLevelTypeis5:
//*************************************************5 格
		if((WHOSYS>145)||(WHODIA>95))
			{	
				WHOLevel=5;
				if(KeyNumber!=7) WHOLevel5Icon;
				if(KeyNumber!=7) WHOLevel4Icon;
				if(BLFlag)
				{
					OutGreenOff;//OutGreen=0;
					OutRedOn;//OutRed=1;
				}
				return;
			}	
		if((WHOSYS>=135)||(WHODIA>=85))
			{			
				WHOLevel=4;
				if(KeyNumber!=7) WHOLevel4Icon;
				if(BLFlag)
				{
					OutGreenOff;//OutGreen=0;
					OutRedOn;//OutRed=1;
				}
				return;
			}		
		if((WHOSYS>=121)||(WHODIA>=81))
			{	
				WHOLevel=3;
				if(KeyNumber!=7) WHOLevel3Icon;
				if(BLFlag)
				{
					OutGreenOn;//OutGreen=1;
					OutRedOn;//OutRed=1;
				}
				return;
			}				
		if((WHOSYS>=110)||(WHODIA>=70))
			{			
				WHOLevel=2;
				if(KeyNumber!=7) WHOLevel2Icon;
				if(BLFlag)
				{
					OutGreenOn;//OutGreen=1;
					OutRedOff;//OutRed=0;
				}
				return;
			}			
		if((WHOSYS<110)&&(WHODIA<70))
			{
				WHOLevel=1;
				if(KeyNumber!=7) WHOLevel1Icon;
				if(BLFlag)
				{
					OutGreenOn;//OutGreen=1;
					OutRedOff;//OutRed=0;
				}
				return;
			}
Type4:
		if((WHOSYS>=WHOSYS5)||(WHODIA>=WHODIA5))
			{
				WHOLevel=6;
				if(BLFlag)
				{
					OutGreenOff;//OutGreen=0;
					OutRedOn;//OutRed=1;
				}
				WHOLevel6Icon;
				WHOLevel5Icon;
				WHOLevel4Icon;
				WHOLevel3Icon;
				WHOLevel2Icon;
				WHOLevel1Icon;
				return;
			}	
		if((WHOSYS>=WHOSYS4)||(WHODIA>=WHODIA4))
			{
				WHOLevel=5;
				if(BLFlag)
				{
					OutGreenOff;//OutGreen=0;
					OutRedOn;//OutRed=1;
				}
				WHOLevel5Icon;
				WHOLevel4Icon;
				WHOLevel3Icon;
				WHOLevel2Icon;
				WHOLevel1Icon;
				return;
			}		
		if((WHOSYS>=WHOSYS3)||(WHODIA>=WHODIA3))
			{
				WHOLevel=4;
				if(BLFlag)
				{
					OutGreenOff;//OutGreen=0;
					OutRedOn;//OutRed=1;
				}
				WHOLevel4Icon;
				WHOLevel3Icon;
				WHOLevel2Icon;
				WHOLevel1Icon;
				return;
			}			
		if((WHOSYS>=WHOSYS2)||(WHODIA>=WHODIA1))
			{
				WHOLevel=3;
				if(BLFlag)
				{
					OutGreenOff;//OutGreen=0;
					OutRedOn;//OutRed=1;
				}
				WHOLevel3Icon;
				WHOLevel2Icon;
				WHOLevel1Icon;
				return;
			}				
		if((WHOSYS>=WHOSYS1)&&(WHODIA<WHODIA1))
			{
				WHOLevel=2;
				if(BLFlag)
				{
					OutGreenOn;//OutGreen=1;
					OutRedOn;//OutRed=1;
				}
				WHOLevel2Icon;
				WHOLevel1Icon;
				return;
			}			
		if((WHOSYS<WHOSYS1)&&(WHODIA<WHODIA1))
			{
				WHOLevel=1;
				if(BLFlag)
				{
					OutGreenOn;//OutGreen=1;
					OutRedOff;//OutRed=0;
				}
				WHOLevel1Icon;
				return;
			}
}


void EngTurDisplay(void)	//英土显示
{
	if(VoiceType==4)
	{
		if(VoiceFlag==1)
			{
				mmHgIconOn;
				kPaIconOff;
			}
		else
			{
				kPaIconOn;
				mmHgIconOff;
			}
		}
	else
	{
		SPDisplay();	
	}
}



void SPDisplay(void)		//普通话粤语设置
{
	DisplayHalfByte(0x5,SYSTen);
	DisplayHalfByte(0x1b,SYSSingle);
	if(VoiceFlag==1)
	{
		DisplayHalfByte(1,DIASingle);
	}
	else
	{
		DisplayHalfByte(2,DIASingle);
	}
}

void ShowVoiceCET(void)
{
	if(VoiceFlag==0)
	{
		DisplayHalfByte(0xC,DIAHundred);	
		DisplayHalfByte(0x11,DIATen);	
		DisplayHalfByte(0x1C,DIASingle);			//中
	}	
	if(VoiceFlag==1)
	{
		DisplayHalfByte(0xE,DIAHundred);	
		DisplayHalfByte(0x1C,DIATen);	
		DisplayHalfByte(0x9,DIASingle);			//英
	}		
	if(VoiceFlag==2)
	{
		DisplayHalfByte(0x1A,DIAHundred);	
		DisplayHalfByte(0x11,DIATen);	
		DisplayHalfByte(0x1,DIASingle);			//泰语
	}	
}

void ShowVoiceLevel(void)
{
	if(VoiceLevel>0)
	{
		DisplayHalfByte(0x17,DIAHundred);
		DisplayHalfByte(VoiceLevel,DIATen);
		DisplayHalfByte(0x17,DIASingle);
	}
	else
	{
		DisplayHalfByte(0x0,DIAHundred);
		DisplayHalfByte(0xf,DIATen);
		DisplayHalfByte(0xf,DIASingle);
	}
}




void showalarm(void)
{ 
	uint8 D;
  DisplayHalfByte(AlarmMinute[AlarmN]%10,MINSingle);	
  DisplayHalfByte(AlarmMinute[AlarmN]/10,MINTen);	
	if(AMPMLCD&&(AlarmHour[AlarmN]>11)) {PMIconOn;AMIconOff;}	//PM;
	if(AMPMLCD&&(AlarmHour[AlarmN]<12)) {AMIconOn;PMIconOff;}	//AM;
	D=AlarmHour[AlarmN];
	if(AMPMLCD)
		{
			if(D > 11){D -= 12;}
			if(D == 0) D=12;
		} 
	DisplayHalfByte(D%10,HourSingle);
	DarkHourTen1;
	DarkHourTen2;		
	if(D>19){DisplayHour20;}
	else
        {
			if(D>9){DisplayHourTen1;DisplayHourTen2;}
			else{DarkHourTen1;DarkHourTen2;}
		}    	
	TimePointIconOn;
		
	if(AlarmOnOff[AlarmN]==0)
	{
		DisplayHalfByte(0x0,DIAHundred);
		DisplayHalfByte(0xF,DIATen);
		DisplayHalfByte(0xF,DIASingle);
	}
	else
	{
		DisplayHalfByte(0x10,DIAHundred);
		DisplayHalfByte(0x0,DIATen);
		DisplayHalfByte(0x1c,DIASingle);
	}
	
	DisplayHalfByte(0xA,SYSHundred);
	DisplayHalfByte(0x13,SYSTen);
	DisplayHalfByte(AlarmN+1,SYSSingle);	
}

void flashalarm(unsigned char i)
{
	if (T250ms == 0)
	{
		if (OneShot == 1)
		{
			showalarm();			// if 1/4 second to show minute process 
			OneShot=0;
		}
	}
	else
	{
	   	if (OneShot == 0)			// if one shot flag = 0 then 
	     	{
	      		OneShot = 1;		// set on shot flag = 1 
	      		if(i==0) darkwordtolcdhour();
				else if(i==1) darkwordtolcdmin();
				else if(i==2)
				{
					DisplayHalfByte(0x10,DIAHundred);
					DisplayHalfByte(0x10,DIATen);
					DisplayHalfByte(0x10,DIASingle);							
				}
	     	}
	}	
}



void SpeakDisplay(void)
{
	DarkAllIcon();
	if(KeyNumber==7)
	{
		VoiceOffIconOn;
		if(VoiceEnable==1)
		{
			DisplayHalfByte(0x00,DIAHundred);
			DisplayHalfByte(0x1c,DIATen);
		}
		else
		{
			DisplayHalfByte(0x00,DIAHundred);
			DisplayHalfByte(0x0f,DIATen);
			DisplayHalfByte(0x0f,DIASingle);	
		}		
	}
	else
	{
		//DisplayHalfByte(0x05,SYSHundred);
		DisplayHalfByte(0x05,SYSTen);
		DisplayHalfByte(0x1b,SYSSingle);

		if(VoiceEnable==1)
		{
			DisplayHalfByte(0x00,DIATen);
			DisplayHalfByte(0x1c,DIASingle);
		}
		else
		{
			DisplayHalfByte(0x00,DIAHundred);
			DisplayHalfByte(0x0f,DIATen);
			DisplayHalfByte(0x0f,DIASingle);	
		}
	}
}	



void flashCL(void)
{
	DarkAllIcon();
	N=0;
	DisplayHalfByte(0x0c,DIATen);		// 'C' 
	DisplayHalfByte(0x13,DIASingle);	// 'L'
	MemoryIconOn;//MarkMEMORY = 1;
	BUZZER_EN;
	delay(32);
	do{
		BUZZER_DIS;
	    DisplayHalfByte(0x10,DIATen);		// 'NULL' 
     	DisplayHalfByte(0x10,DIASingle);	// 'NULL'
	    delay(8);
	    DisplayHalfByte(0x0c,DIATen);		// 'C' 
	    DisplayHalfByte(0x13,DIASingle);	// 'L'
	    BUZZER_EN;
	    delay(8);
	    BUZZER_DIS;
		N++;
		}while(N<4);
	do{}while(KEY_MEMORYDOWN==0);
	do{}while(KEY_MEMORYUP==0);
	keydelay();
    DarkAllIcon();
}


void ShowRestTime(uint32 TimeCount)
{
	uint32 temp;
	temp=TimeCount/60;
	TimeCount%=60;
	DarkHourTen1;
	DarkHourTen2;
	DisplayHalfByte(temp%10,HourSingle);
	if(temp>19) {DisplayHour20;}
	else if(temp>9)
	{
		DisplayHourTen1;
		DisplayHourTen2;
	}
	DisplayHalfByte(TimeCount/10,MINTen);
	DisplayHalfByte(TimeCount%10,MINSingle);
	TimePointIconOn;
}


void ShowMemoryDate(unsigned char MM,unsigned char DD)
{
   
	DisplayHalfByte(MM%10,MonthSingle);
	DisplayHalfByte(DD%10,DaySingle);	
    DisplayHalfByte(DD/10,DayTen);	
	if(MM>9){MonthTenIconOn;}	
	else{MonthTenIconOff;}   
	MonthIconOn;
	DayIconOn;
}
/************************************************/
void ShowMemoryTime(unsigned char HH,unsigned char MM)
{
	if(AMPMLCD&&(HH>11)) {PMIconOn;AMIconOff;}	//PM;
	if(AMPMLCD&&(HH<12)) {AMIconOn;PMIconOff;}	//AM;	
  if(AMPMLCD)
  	{ 
  		if(HH==0){HH=12;} 			//20101212新增12小时制时,0点即为12点
  		else{if(HH>12){HH-=12; }}
  	}
  TimeTenIconOff1;TimeTenIconOff2;
	DisplayHalfByte(HH%10,HourSingle); 
	DisplayHalfByte(MM%10,MINSingle);	
	DisplayHalfByte(MM/10,MINTen);
	TimePointIconOn;				// :
	if(HH>19){DisplayHour20;}			// 2 
	else
		{	
			if(HH>9){Time1IconOn1;Time1IconOn2;}	//1
			else{TimeTenIconOff1;TimeTenIconOff2;}        
		}  
}


void lowbsignon(void)
{  
   	LBTIconOn;
}


void LCDTEST(void)
{
	uint8 i;
	for(i=0;i<28;i++)
	{
		DisplayHalfByte(i,7);
		DisplayHalfByte(i,13);
		delay(75);
	}
	
	
	
	UserAIconOn;
	nop4();
	UserAIconOff;
	nop4();
	UserAIconOn;
	nop4();
	UserBIconOn;
	nop4();
	UserBIconOff;
	nop4();
	UserBIconOn;
	nop4();
	MonthTenIconOn;
	nop4();
	MonthTenIconOff;
	nop4();
	MonthTenIconOn;
	nop4();
	MonthIconOn;
	nop4();
	MonthIconOff;
	nop4();
	MonthIconOn;
	nop4();
	AMIconOn;
	nop4();
	AMIconOff;
	nop4();
	AMIconOn;
	nop4();
	PMIconOn;
	nop4();
	PMIconOff;
	nop4();
	PMIconOn;
	nop4();
	Time1IconOn1;
	nop4();
	Time1IconOn2;
	nop4();
	Time2IconOn;
	nop4();
	TimeTenIconOff1;
	nop4();
	TimeTenIconOff2;
	nop4();
	TimePointIconOn;
	nop4();
	TimePointIconOff;
	nop4();
	TimePointIconOn;
	nop4();
	kPaPointSYSIconOn;
	nop4();
	kPaPointSYSIconOff;
	nop4();
	kPaPointSYSIconOn;
	nop4();
	kPaPointDIAIconOn;
	nop4();
	kPaPointDIAIconOff;
	nop4();
	kPaPointDIAIconOn;
	nop4();
	MemoryIconOn;
	nop4();
	MemoryIconOff;
	nop4();
	MemoryIconOn;
	nop4();
	/*PADIconOn;
	nop4();
	PADIconOff;
	nop4();
	PADIconOn;
	nop4();
	LBTIconOn;
	nop4();
	LBTIconOff;
	nop4();
	LBTIconOn;
	nop4();
	HeartIconOn;
	nop4();
	HeartIconOff;
	nop4();
	HeartIconOn;
	nop4();
	PULBAIIconOn;
	nop4();
	PULBAIIconOff;
	nop4();
	PULBAIIconOn;
	nop4();*/
	mmHgIconOn;
	nop4();
	mmHgIconOff;
	nop4();
	mmHgIconOn;
	nop4();
	kPaIconOn;
	nop4();
	kPaIconOff;
	nop4();
	kPaIconOn;
	nop4();
	WHOLevel1Icon;
	nop4();
	WHOLevel2Icon;
	nop4();
	WHOLevel3Icon;
	nop4();
	WHOLevel4Icon;
	nop4();
	WHOLevel5Icon;
	nop4();
	WHOLevel6Icon;
	nop4();
	WHOLevelIconOff;
	nop4();
	DisplayYear20;
	nop4();
	DarkHourTen1;
	nop4();
	DarkHourTen2;
	nop4();
	DisplayYear20;
	nop4();


}

/*----------------------------------------------------------
 * 函数功能：整体初始化LCD相关参数，包括CPR,VLCD电平的设置
 * 入口参数：None
 * 出口参数：None
 * 返回值  ：None
 * 编写日期：
 * 作者    ：
 *---------------------------------------------------------*/ 
void user_lcd_stru_init(void)
 {
    LCD_InitTypeDef LCD_InitStruct;
    LCD_InitStruct.BIAS = DISABLE; // 20211108  1/3 change to 1/4
    LCD_InitStruct.LCDBL = ENABLE;
    LCD_InitStruct.LCDDUTY = LCDDUTY_6COM;      // 20210713
    LCD_InitStruct.LCDCLKS = LCDCLKS_ILRC_DIV2; //
    LCD_InitStruct.LCDCLKS_DIV = LCDCLKS_DIV4;  // 20210723 64 to 32
    LCD_InitStruct.LCDWAVE = LCDWAVE_B;

    LCD_InitStruct.LCDPin_Mode_COM = 0xff;        // 6com && seg 2 3
    LCD_InitStruct.LCDPin_Mode_SEG1 = 0xfcff8000; //seg 4 ~ 31
    LCD_InitStruct.LCDPin_Mode_SEG2 = 0x03f;      //seg 32 ~ 43
    LCD_Init(&LCD_InitStruct);
    LCD_CPRCmd(ENABLE);
    LCD_CPRCLKConfig(LCD_IHRC_DIV8);        //
    LCD_VLCDLevelConfig(LCD_VLCDLevel_3V6); // 20211108 3v6 change to 4v2
    // LCD_CPRCmd(ENABLE);
    LCD_Cmd(ENABLE);
    LCD_ClearDisALL();
 }


























